<template>
	<view class="storePage">
		<!-- <button @click="login">登录</button> -->
		<!-- 头部-->
		<view class="header" :style="{paddingTop:`${menuButton.top}rpx`}">
			<!-- 选择地址 -->
			<!-- 	<view class="address" @click="showPois">
				<uni-icons type="location" size="19" color="#000" @click="showPois"></uni-icons>
				<text>{{ myAddress.addressName ? myAddress.addressName : '请选择配送地址' }}</text>
				<uni-icons type="down" size="16" color="#000" @click="showPois"></uni-icons>
				<view @click.stop="getAddressAuth">
					<uni-icons class="refreshempty" type="refreshempty" size="19" color="#000"></uni-icons>
				</view>
			</view> -->
			<view class="address">{{userInfo.companyName}}</view>
			<!-- 搜索框 -->
			<view class="search">
				<uni-icons class="searchIcon" type="search" size="25" color="#ccc"></uni-icons>
				<!-- <i></i> -->
				<input type="text" confirm-type="search" @confirm="queryStoresByKeywordFn" v-model="keyword"
					placeholder="搜索你想要的内容">
				<!-- <view class="btn" @click="queryStoresByKeywordFn">搜索</view> -->
			</view>
		</view>
		<!-- 内容 -->
		<view class="content">
			<!-- 大厦列表 -->
			<!-- 	<view class="buildings" v-if="buildingsList.length">
				<view class="buildings_title">点击查看各个收货地址图片</view>
				<view class="buildings_list">
					<template v-for="(item,index) in buildingsList">
						<view class="buildings_item" v-if="index <= 3" @click="goBuildingDetails(item.buildingName)"
							:key="item.buildingName">
							<image :src="item.buildingIconUrls"></image>
							<view>{{item.buildingName}}</view>
						</view>
					</template>

					<view class="more" v-if="buildingsList.length >= 4" @click="moreBuilding">
						更多
					</view>
				</view>
			</view> -->
			<!-- 其他客户提醒  营销 -->
			<!-- 	<view class="notice">
				<text>0~一荤两素12-1414:42</text>
				<view @click="orderListShow">查看详情 <uni-icons type="right" size="14"></uni-icons></view>
			</view> -->
			<!-- 倒计时  -->
			<!-- <view class="countdown">
				<view class="countdown_title">目前下单人已有<text>{{payedOrderCount}}</text>位用户下单</view>
				<view class="countdown_time">
					<view class="title">距结束</view>
					<view class="countdown_content">
						<view class="">
							<Flipper :total="2" :current="countInfo.systemHour1"></Flipper>
							<Flipper :total="9" :current="countInfo.systemHour2"></Flipper>
						</view>
						<view class="point">:</view>
						<view class="">
							<Flipper :total="5" :current="countInfo.systemMinute1"></Flipper>
							<Flipper :total="9" :current="countInfo.systemMinute2"></Flipper>
						</view>
						<view class="point">:</view>
						<view class="">
							<Flipper :total="5" :current="countInfo.systemSecound1"></Flipper>
							<Flipper :total="9" :current="countInfo.systemSecound2"></Flipper>
						</view>
					</view>
				</view>
			</view> -->
			<view class="store_title">
				热门店铺
			</view>
			<!-- 商家列表 -->
			<view class="hotelBox" v-if="shopList.length != 0">

				<view class="hotellList" @click="showStoreDet(item)" v-for="(item, index) in shopList" :key="index">
					<view class="hotelInfo">
						<image :src="item.storeLogo" mode="aspectFill"></image>
						<view class="topRight">
							<view class="">
								<view class="">{{ item.storeName }} </view>
								<view class="notEnd" v-if="countInfo[`hour${index}`] != undefined">
									<!-- 营业时间 -->
									<view class="">距结束</view>
									<view class="">
										{{ countInfo[`hour${index}`] }}:{{ countInfo[`minute${index}`] }}:{{ countInfo[`secound${index}`] }}
									</view>
								</view>
								<view class="end" v-else>
									营业时间
									<text>歇业中</text>
								</view>
							</view>

							<view class="">
								<view class="">
									营业时间
									<text>{{  item.businessTime }} </text>
								</view>
							</view>
							<view class="">
								<view class="">
									<!-- 综合评分 -->
									<uni-icons type="star-filled" size="18" color="#FF1010"></uni-icons>
									<text>{{ item.scores  || '5.0'}}分</text>
								</view>
								<view class="">
									月售{{ item.saleCount || 0}}
								</view>

							</view>
							<!-- <view class="">{{ item.storeDescription }}</view> -->
							<view class="coupons">
								<view v-for="items in item.coupons" :class="items.received ? 'received' : ''"
									@click.stop="claimCoupons(item,items)">{{items.couponName}}
									<text>{{items.received ? '已领取' : '立即领取'}}</text>
								</view>
							</view>
						</view>
					</view>
					<view class="shopContent">
						<template v-for="(foodItem, foodIndex) in item.foods">
							<view class="shopList" v-show="foodIndex <= 2" :key="foodIndex">
								<view class="imgContent">
									<image :lazy-load="true" :src="foodItem.foodImage" :loading-img="loadingImg"
										img-mode=""></image>
								</view>
								<view class="shopInfo">
									<view class="shopName">{{ foodItem.foodName }}</view>
									<view class="control">

										<view class="surplus">
											<view>
												<text class="price">
													<text>￥</text>
													{{ foodItem.foodShowPrice | fenToYuan }}
												</text>
											</view>
										</view>
									</view>
								</view>
							</view>
						</template>

					</view>
				</view>
			</view>
			<empty text="没有找到相关数据" v-if="shopList.length == 0"></empty>
		</view>


		<!-- 当前已下单用户详情 -->
		<view class="orderContent">
			<uni-popup ref="orderContent" type="center" background-color="#fff">
				<div class="orderDet">
					<view>{{ myAddress.addressName }}</view>
					<!-- <view class="">目前已有【{{countInfo.personNum}}】位用户成功下单</view> -->
					<view>目前已有【{{ orderList&&orderList.length!=0?orderList[0].pickingSerialNo:0 }}】位用户成功下单</view>
					<template v-if="orderList.length != 0">
						<view class="listContent" id="listContent">
							<view class="list" v-for="(item, index) in orderList" :key="index">
								<view>{{ item.pickingSerialNo }}</view>
								<view>{{ item.nameTakingMeal }}</view>
								<view>{{ item.nameDishes }}</view>
								<view>{{ item.createTimeStr }}</view>
							</view>
						</view>
					</template>
					<empty text="暂时还没有人下单哦" v-if="orderList.length == 0"></empty>
				</div>
			</uni-popup>
		</view>


		<!-- 地址列表 -->
		<posiBottom ref="posiBottom" @checkThisAddress="checkThisAddress"> </posiBottom>
		<!-- 小程序登录 -->
		<login @loginSuccess="loginSuccess" :auth.sync="auth"></login>
		<!-- 规格 -->
		<specBox ref="specBox" :addressId="myAddress.addressId" @getShopCar="getShopCar" :specInfo="specInfo"></specBox>

		<!-- 购物车 -->
		<shopCar :siteAddrId="myAddress.addressId" ref="shopCar" @setMustPurchase="setMustPurchase"
			:mustPurchaseShowToast="false" :footerB="120"></shopCar>
		<!-- 店铺详情 myAddress.addressId-->
		<!-- <storeDetails :shopCarList="shopCarInfo.shopCarList" :storeId="storeId" :siteAddrId="myAddress.addressId"
			@getShopCar="getShopCar" @hideStoreDetails="showStoreDetails = false" ref="storeDetails"
			v-show="showStoreDetails"></storeDetails> -->

		<!-- 加载动画 -->
		<loading :showLoading="showLoading" text="数据加载中"></loading>


		<!-- 大厦列表 -->
		<buildingList ref="buildingList" :buildingsList="buildingsList"></buildingList>

		<custom-tab-bar :items="tabItems" :currentIndex="currentTab" @item-click="onTabClick" :color="color"
			:selectedColor="selectedColor"></custom-tab-bar>
	</view>
</template>

<script>
	import MyMinix from '@/utils/minix/minix.js';
	import util from "@/utils/util.js";
	import CustomTabBar from '@/uni_modules/niceui-tabBar/components/niceui-tabBar/niceui-tabBar.vue';
	import tabbar from '@/uni_modules/niceui-tabBar/common/tabbar.js'
	// import Flipper from '@/components/Flipper/Flipper.vue';
	import {
		mapState,
		mapGetters
	} from 'vuex'
	import {
		queryBuildingBriefInfoBySiteId,
		queryNearnestSiteAddrByLongLat,
		queryStoresByKeyword,
		receiveCoupon,
	} from "@/request/api.js";
	export default {
		mixins: [MyMinix],
		components: {
			CustomTabBar
			// Flipper,
		},
		// 获取 vuex里的购物车信息
		computed: {
			shopCarInfo() {
				return this.$store.getters.getShopCarInfo
			}
		},
		// 数据监听
		// watch: {
		// 	// 购物车数据改变了
		// 	shopCarInfo: {
		// 		handler(val) {
		// 			this.shopList.forEach(items => {
		// 				items.foods.forEach(items1 => {
		// 					let items2 = val.shopCarList.map(item => item).filter(item => item.foodId ==
		// 						items1.foodId)
		// 					if (items1.count == 1 && !items2) {
		// 						items1.count = 0;
		// 					}
		// 					console.log(items2, 'items2');
		// 					if (items2.length) {
		// 						this.$set(items1, 'count', items2.reduce((num, item) => num + item.count,
		// 							0))
		// 					}
		// 				})
		// 			})
		// 		},
		// 		deep: true, //深度监听 
		// 		immediate: true //第一次设置数据触发
		// 	}
		// },
		data() {
			return {
				util, //公共方法
				showLoading: false, //显示加载动画
				loadingImg: '../../static/loading.png',
				// 小程序授权弹窗 false 不显示 true 显示 
				auth: false,
				buildingsList: [], //店铺分类
				orderList: [], //已下单用户列表
				//系统倒计时的信息
				countInfo: {
					personNum: 0,
					// hour: '00',
					// minute: '00',
					// secound: '00',
					systemSecound1: 0,
					systemSecound2: 0,
					systemMinute1: 0,
					systemMinute2: 0,
					systemHour1: 0,
					systemHour2: 0,
					timer: ''
				},
				keyword: '', //搜索输入框文字
				myAddress: {
					addressId: '', //大厦id  //1693633601729568769 //1740680071424454658
					addressName: '' //大厦名称
				}, //我当前的位置
				shopList: [], //店铺列表
				storeId: '', // 店铺id
				hasAllCheck: false, //购物车全选按钮的状态，
				specInfo: {}, //菜品规格
				newUserCouponPackage: {}, //判断是否为新用户信息
				isLoad: false, //判断是否第一次加载 ，用于显示购物车数据
				menuButton: {},
				currentTab: 1, // 当前选中的tab索引
				tabItems: tabbar.tabItems,
				color: tabbar.color,
				selectedColor: tabbar.selectedColor,
				storePage: {
					siteAddressList: '',
					addressList: '',
					storeList: '',
					shopBusinessTime: ''
				},
				isClick: false,
				userInfo:{}
			}
		},
		onShareAppMessage() {
			return {
				title: '祥瑜团餐',
				path: '/pages/storeList/storeList',
				imageUrl: ''
			}
		},
		// 只有首次进入 执行一次，后续不执行
		async onLoad(options) {
			this.isLoad = true;
			// 获取选择的地址
			let datas = util.getStorePage();
			
			// let currAddress = datas['currAddress'];
			// 获取当前位置最匹配的大厦
			// if (!currAddress) {
			// 	await this.getAddressAuth();
			// } else {
			// 	this.myAddress = currAddress
			// 
			// }
		},
		// 每次进入首页都会执行
		async onShow() {
			this.menuButton = util.getMenuButton()
				let userInfo = uni.getStorageSync('userInfo');
				this.userInfo = userInfo || {};
			if (this.countInfo.timer) {
				clearInterval(this.countInfo.timer);
			}
			// 如果不是第一次 访问 获取vuex里的 购物车信息
			if (!this.isLoad) {
				this.$refs.shopCar.getVuexShopCarInfo();
			}
			this.initData()
			this.isLoad = false;
			this.isClick = false;
		},
		methods: {
			setMustPurchase(item) {
				let that = this;
				if (!that.isClick) {
					that.isClick = true;
					util.goToUrl(
						`/pages/storeDetails/storeDetails?storeId=${item.storeId}&siteAddrId=${that.myAddress.addressId}&mustPurchase=1`
						)
				}
			},
			onTabClick(index) { // 切换tab的函数，当选中某个tab时触发
				//this.currentTab = index;  
				if (index != this.currentTab) {
					util.goToUrl(this.tabItems[index].pagePath, index == 0 ? 'reLaunch' : 'redirectTo')
				}
			},
			// 跳转大厦存放点
			goBuildingDetails(name) {
				// buildingDetails
				util.goToUrl(
					`/pages/buildingDetails/buildingDetails?name=${name}`)
			},

			// 显示登录弹窗 
			login() {
				let token = uni.getStorageSync('token');
				if (!token) {
					this.auth = true;
				}
			},
			// 其他用户下单显示
			orderListShow() {
				this.$refs.orderContent.open('center')
			},
			// 登录成功 隐藏登录弹窗 初始化数据
			loginSuccess() {
				this.auth = false;
				this.initData();
			},

			// 判断是否有获取当前位置权限 ， 如果有直接获取，没有则需要用户点击授权
			async getAddressAuth() {
				let that = this;
				// 获取用户是否开启 授权获取当前的地理位置、速度的权限。
				await uni.getSetting({
					success: async (res) => {
						// 如果没有授权
						if (!res.authSetting['scope.userLocation']) {
							// 则拉起授权窗口
							uni.authorize({
								scope: 'scope.userLocation',
								success: async (res) => {
									//点击允许后--就一直会进入成功授权的回调 就可以使用获取的方法了
									await that.getTheCurrentAddress();
								}
							})
						} else {
							await that.getTheCurrentAddress();
						}
					}
				})
			},

			// 获取当前位置最匹配的大厦
			async getTheCurrentAddress() {
				let that = this;
				await uni.getLocation({
					type: 'gcj02',
					// type: 'wgs84',
					geocode: true,
					highAccuracyExpireTime: 6000,
					isHighAccuracy: true, //是否开启高精度
					success: async function(res) {
						let latlon = {
							latitude: res.latitude,
							longitude: res.longitude
						}
						// uni.setStorageSync('latlon',JSON.stringify(latlon))
						that.latlon = latlon;
						// 根据经纬度 获取距离最近的大厦
					
					},
					fail: function(err) {
						console.log(err, 'err');
					}
				});
			},

			// 根据经纬度 获取距离最近的大厦
			async queryNearnestSiteAddrByLongLatFn() {
				let address = await queryNearnestSiteAddrByLongLat({
					method: "GET",
					data: {
						latitude: this.latlon.latitude,
						longitude: this.latlon.longitude
					},
				})
				this.myAddress.addressId = address.result.nearnestAddrId;
				this.myAddress.addressName = address.result.nearnestAddrName;
				util.setStorePage([{
					name: 'currAddress',
					data: this.myAddress
				}]);
				this.initData();
			},



			// 初始数据
			async initData() {
				uni.removeStorageSync("mustSelectedFoodsStorage");
				this.showLoading = true;
				let token = uni.getStorageSync('token');
			
				if(!this.userInfo ||  !this.userInfo?.companyId) {
					uni.showToast({
						title:"未登录,请先登录!",
						icon:'none'
					})
					this.showLoading = false;
					return
				};
				//根据店铺或菜品名进行模糊搜索
				await this.queryStoresByKeywordFn();

				// 根据站点id获取站点下的大厦列表和按钮icon图标
				// this.queryBuildingBriefInfoBySiteIdFn();
				if (token) {
					// 购物车列表
					this.getShopCar();
				}
				this.showLoading = false;
			},
			// 显示地址列表
			showPois() {
				this.$refs.posiBottom.showPois();
			},

			/**
			 *  选择地址
			 * data：地址列表选择的地址信息
			 * */
			checkThisAddress(data) {
				util.setStorePage([{
					name: 'currAddress',
					data
				}]);
				this.myAddress = data;
				this.$refs.posiBottom.$refs.popup.close()
				this.initData();
			},

			/** 根据店铺名或菜品名进行模糊搜索
			 **/
			async queryStoresByKeywordFn() {
				// let datas = this.getStorePage();
				// let shopBusinessTime = datas['shopBusinessTime']
				// let storeList = datas['storeList']
				// if (shopBusinessTime && storeList) {
				// 	storeList.map(item=>{
				// 		this.initCountDown('store', item);
				// 		util.setMustSelectedFoods(item,item.mustSelectedFoods);
				// 	})
				// 	this.shopList = storeList;

				// 	return;
				// 
				// }
			
				let res = await queryStoresByKeyword({
					method: "GET",
					data: {
						companyId:this.userInfo.companyId, //用户办公地点大厦Id，由接口1.1自动定位 或 1.2 用户手动选择的大厦的Id；
						departId:this.userInfo.departId, //员工部门id
						keyword: this.keyword, //在搜索框中输入的关键字，菜品名称或部分，用户没有在输入框中输入搜索条件时，此字段传递null 即可；
						
						// pageNo: 1, //从1开始，分页查询
						// pageSize: 10 //每页数据行数，比如10
					}
				});

				// if (res.code == 200) {
					// res = {
					// 	"success": true,
					// 	"message": "",
					// 	"code": 200,
					// 	"result": [{
					// 		"storeDescription": "",
					// 		"businessHoursBegin": "12:00:00",
					// 		"qualifications": "",
					// 		"score": 5.0,
					// 		"foods": [{
					// 			"foodId": "1767102779534716929",
					// 			"foodName": "中式健康菜，敬请期待！",
					// 			"foodDescription": null,
					// 			"foodImage": "https://customer.qiyetuancan.com/static/images/1752954257129803777/foods/4221c1e1-cc04-46be-9c96-65b8238d5a03-图标1.jpg",
					// 			"salePrice": 2100,
					// 			"specifications": [{
					// 				"type": "主食",
					// 				"items": [{
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "白米饭"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "杂粮饭"
					// 				}]
					// 			}, {
					// 				"type": "菜品一",
					// 				"items": [{
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "金汤酸菜鱼"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "葱香鸡腿肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "萝卜炖牛腩"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "蒜香蘑菇鸡胸肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "香菇滑鸡"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "杏鲍菇牛肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "海鲜菇炒鸡胸肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "虾仁炒蛋"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "番茄炒蛋"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "外婆菜肉沫"
					// 				}]
					// 			}],
					// 			"limitCount": 100,
					// 			"sort": 72,
					// 			"required": false
					// 		}, {
					// 			"foodId": "1769294874361991170",
					// 			"foodName": "中式健康菜4，敬请期待！",
					// 			"foodDescription": null,
					// 			"foodImage": "https://customer.qiyetuancan.com/static/images/1752954257129803777/foods/4221c1e1-cc04-46be-9c96-65b8238d5a03-图标1.jpg",
					// 			"salePrice": 1250,
					// 			"specifications": [{
					// 				"type": "主食",
					// 				"items": [{
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "白米饭"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "杂粮饭"
					// 				}]
					// 			}, {
					// 				"type": "菜品一",
					// 				"items": [{
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "金汤酸菜鱼"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "葱香鸡腿肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 998,
					// 					"storePrice": 0,
					// 					"name": "萝卜炖牛腩"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "蒜香蘑菇鸡胸肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "香菇滑鸡"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "杏鲍菇牛肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "海鲜菇炒鸡胸肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "虾仁炒蛋"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "番茄炒蛋"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "外婆菜肉沫"
					// 				}]
					// 			}, {
					// 				"type": "菜品二",
					// 				"items": [{
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "金汤酸菜鱼"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "葱香鸡腿肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "萝卜炖牛腩"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "蒜香蘑菇鸡胸肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "香菇滑鸡"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "杏鲍菇牛肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "海鲜菇炒鸡胸肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "虾仁炒蛋"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "番茄炒蛋"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "外婆菜肉沫"
					// 				}]
					// 			}],
					// 			"limitCount": 100,
					// 			"sort": 73,
					// 			"required": false
					// 		}, {
					// 			"foodId": "1769294971074252801",
					// 			"foodName": "中式健康菜5，敬请期待！",
					// 			"foodDescription": null,
					// 			"foodImage": "https://customer.qiyetuancan.com/static/images/1752954257129803777/foods/4221c1e1-cc04-46be-9c96-65b8238d5a03-图标1.jpg",
					// 			"salePrice": 300,
					// 			"specifications": [{
					// 				"type": "主食",
					// 				"items": [{
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "白米饭"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "杂粮饭"
					// 				}]
					// 			}, {
					// 				"type": "菜品一",
					// 				"items": [{
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "金汤酸菜鱼"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "葱香鸡腿肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "萝卜炖牛腩"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "蒜香蘑菇鸡胸肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 998,
					// 					"storePrice": 0,
					// 					"name": "香菇滑鸡"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "杏鲍菇牛肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "海鲜菇炒鸡胸肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "虾仁炒蛋"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "番茄炒蛋"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 998,
					// 					"storePrice": 0,
					// 					"name": "外婆菜肉沫"
					// 				}]
					// 			}, {
					// 				"type": "菜品二",
					// 				"items": [{
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "金汤酸菜鱼"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "葱香鸡腿肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "萝卜炖牛腩"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "蒜香蘑菇鸡胸肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "香菇滑鸡"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "杏鲍菇牛肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "海鲜菇炒鸡胸肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "虾仁炒蛋"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "番茄炒蛋"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "外婆菜肉沫"
					// 				}]
					// 			}, {
					// 				"type": "菜品三",
					// 				"items": [{
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "金汤酸菜鱼"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "葱香鸡腿肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "萝卜炖牛腩"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "蒜香蘑菇鸡胸肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "香菇滑鸡"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "杏鲍菇牛肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "海鲜菇炒鸡胸肉"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "虾仁炒蛋"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "番茄炒蛋"
					// 				}, {
					// 					"salePrice": 0,
					// 					"limitCount": 999,
					// 					"storePrice": 0,
					// 					"name": "外婆菜肉沫"
					// 				}]
					// 			}],
					// 			"limitCount": 100,
					// 			"sort": 74,
					// 			"required": false
					// 		}],
					// 		"coupons": [],
					// 		"businessHoursEnd": "10:30:00",
					// 		"storeLogo": "https://customer.qiyetuancan.com/static/images/1752954257129803777/logo/07292ea3-fed8-4d62-b377-efe611841ecd-截图2.png",
					// 		"storeName": "深食堂-健康小碗菜",
					// 		"storeId": "1752954257129803777",
					// 		"mustSelectedFoods": [],
					// 		"sales": 999
					// 	}],
					// 	"timestamp": 1717596340292
					// } 
					this.setShopList(res.data);
				// }

			},

			// 根据站点id获取站点下的大厦列表和按钮icon图标
			async queryBuildingBriefInfoBySiteIdFn() {
				let datas = this.getStorePage();
				let buildingsList = datas['buildingsList']
				if (buildingsList) {
					this.buildingsList = buildingsList;
					return;
				}
				let res = await queryBuildingBriefInfoBySiteId({
					method: "GET",
					data: {
						siteId: this.myAddress.addressId, //用户所在大厦Id；
					}
				});
				if (res.code == 200) {
					let build = res.result.buildings;
					this.buildingsList = build;
					util.setStorePage([{
						name: 'buildingsList',
						data: build
					}, ]);
				}
			},

			// 更多大厦列表
			moreBuilding() {
				;
				this.$refs.buildingList.$refs.popup.open()
			},

			// 设置店铺列表信息
			setShopList(data) {
				this.shopList = [];
				let shopBusinessTime = [];
				data.forEach(item => {
					item.businessHours = JSON.stringify([{
						startTime: item.storeBusinessStart,
						endTime: item.storeBusinessEnd
					}])
					item.businessTime = item.storeBusinessStart + '~' + item.storeBusinessEnd;
					shopBusinessTime.push({
						storeId: item.storeId,
						storeName: item.storeName,
						businessTime: item.businessTime
					})
					this.initCountDown('store', item);
					this.shopList.push(item);
					util.setMustSelectedFoods(item, item.mustSelectedFoods);
				});
				// this.storePage.storeList = JSON.stringify(this.shopList)
				// uni.setStorageSync('shopBusinessTime', JSON.stringify(shopBusinessTime));

				util.setStorePage([{
						name: 'storeList',
						data: this.shopList
					},
					{
						name: 'shopBusinessTime',
						data: shopBusinessTime
					},
				]);
			},

			// 显示店铺详情
			showStoreDet(item) {
				util.goToUrl(
					`/pages/storeDetails/storeDetails?storeId=${item.storeId}&siteAddrId=${this.myAddress.addressId}`)
			},

			// 领取优惠券
			async claimCoupons(item, items) {
				let token = uni.getStorageSync('token');
				if (!token) {
					this.auth = true;
					return;
				}
				if (items.received) {
					uni.showToast({
						title: '已经领取，不能重复领取!',
						icon: 'none'
					})
					return;
				}
				let res = await receiveCoupon({
					method: "POST",
					data: {
						"siteId": this.myAddress.addressId,
						"storeId": item.storeId,
						"couponId": items.couponId,
					},
				})
				let isSuccess = res.code == 200;
				uni.showToast({
					title: isSuccess ? '领取成功!' : res.message,
					icon: isSuccess ? 'success' : 'none'
				})
				isSuccess && this.$set(items, 'received', true);
			},

			//展示商品规格选择弹窗
			showSpecAlert(item, foodItem) {
				let token = uni.getStorageSync('token');
				if (!token) {
					this.auth = true;
					return;
				}
				this.specInfo = foodItem
				this.$nextTick(() => {
					this.$refs.specBox.showSpec()
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.storePage {
		padding: 250rpx 0 130rpx;
	}

	// 头部
	.header {
		position: fixed;
		top: 0;
		width: calc(100% - 60rpx);
		background: #fff;
		color: #333;
		padding: 30rpx 30rpx 40rpx;
		z-index: 1;

		// 选择地址
		.address {
			display: flex;
			align-items: center;
			padding-bottom: 30rpx;

			text {
				display: inline-block;
				max-width: 80%;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				padding: 0 5rpx;
			}

			.refreshempty {
				margin-left: 10rpx;
			}
		}

		// 搜索框
		.search {
			display: flex;
			align-items: center;
			justify-content: space-between;
			width: 100%;
			height: 60rpx;
			padding: 5rpx 0;
			background: #F6F6F6;
			font-size: 32rpx;
			color: #000;
			// margin-top: 20rpx;
			border-radius: 16rpx;

			&Icon {
				margin-left: 15rpx;
			}

			input {
				display: inline-block;
				width: 100%;
				height: 100%;
				padding-left: 10px;
			}

			// .btn {
			// 	color: #35AA4C;
			// 	font-size: 28rpx;
			// 	width: 100rpx;
			// 	height: 90rpx;
			// 	line-height: 90rpx;
			// 	text-align: center;
			// }
		}
	}


	.swiper {
		height: 400rpx;

		image {
			display: block;
			width: 100%;
			height: 100%;
		}

	}

	.orderContent {
		/deep/.u-drawer__scroll-view {
			max-height: 50vh;
		}
	}


	.orderDet {
		// -webkit-overflow-scrolling: touch;
		padding: 10rpx;
		min-width: 500rpx;
		min-height: 200rpx;
		border-radius: 10rpx;

		/deep/.noData {
			min-height: 40vh;
		}

		>view:nth-child(1) {
			text-align: center;
			font-size: 32rpx;
			line-height: 2;
		}

		>view:nth-child(2) {
			text-align: center;
			font-size: 28rpx;
			line-height: 2;
		}

		.listContent {
			// max-height: 50vh;
			// min-height: 30vh;
			// overflow-y: scroll;
			// overflow-x: hidden;
			// -webkit-overflow-scrolling: touch;

			>.list {
				@include flexs();
				font-size: 22rpx;
				line-height: 74rpx;
				margin: 20rpx 0;
				padding: 10rpx 0;
				background-color: #f3f3f3;

				>view:nth-child(1) {
					text-align: center;
					width: 10%;
					margin: 0 1%;
				}

				>view:nth-child(2) {
					width: calc(22rpx * 6);
					text-overflow: ellipsis;
					overflow: hidden;
					white-space: nowrap;
				}

				>view:nth-child(3) {
					flex: 1;
					text-overflow: ellipsis;
					overflow: hidden;
					white-space: nowrap;
					margin: 0 1.5%;
				}

				>view:nth-child(4) {
					font-size: 22rpx;
					width: calc(22rpx * 7);
					text-overflow: ellipsis;
					overflow: hidden;
					white-space: nowrap;
				}
			}
		}
	}


	// 内容
	.content {
		position: relative;
		// top: -20rpx;
		padding-bottom: 160rpx;

		// 大厦列表
		.buildings {
			// justify-content: flex-start
			@include flexs(center, flex-start);
			flex-direction: column;
			// justify-content: space-between;
			padding: 0 30rpx 20rpx;
			border-top-left-radius: 15rpx;
			border-top-right-radius: 15rpx;
			background: #fff;

			.more {
				text-align: center;
				width: 92rpx;
				height: 92rpx;
				line-height: 92rpx;
				margin-bottom: 45rpx;
				border: 6rpx solid #000;
				border-radius: 28rpx;
			}

			&_title {
				font-size: 32rpx;
				margin-bottom: 20rpx;
			}

			&_list {
				width: 100%;
				display: flex;
				align-items: center;
				// justify-content: space-between;
				flex-wrap: wrap;
			}

			&_item {
				display: flex;
				flex-direction: column;
				align-items: center;
				// justify-content: space-between;
				text-align: center;
				width: 104rpx;
				margin-right: 42.5rpx;

				&:nth-child(6n) {
					margin-right: 0;
				}

				// width: 148rpx;

				image {
					display: block;
					width: 104rpx;
					height: 104rpx;
				}

				view {
					width: 100%;
					font-size: 22rpx;
					margin-top: 10rpx;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
			}
		}

		// 其他客户提醒  营销 
		.notice {
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-size: 26rpx;
			padding: 20rpx 20rpx;
			border-top: 1rpx solid #dfdfdf;
			border-bottom: 1rpx solid #dfdfdf;

		}

		// 倒计时
		.countdown {
			background: #31CC6C;
			border-radius: 15rpx;
			margin: 20rpx;
			box-shadow: 0rpx 0rpx 5rpx rgba(0, 0, 0, .2);

			// 倒计时标题
			&_title {
				padding: 20rpx;
				font-size: 24rpx;
				color: #FFF;

				text {
					font-size: 34rpx;
					color: #EC3F10;
					font-weight: 600;
					margin: 0 6rpx;
				}
			}

			// 倒计时 时间
			&_time {

				// display: flex;
				// flex-direction: column;
				// align-items: center;
				// justify-content: center;
				// background:#FEECE0;
				// padding:25rpx 0 40rpx;
				// 距结束 标题
				.title {
					color: #887958;
				}

				background:#31CC8E;
				// padding: 40rpx 0 60rpx 0;
				@include flexs(center, center);
				flex-direction: column;
				letter-spacing: 4rpx;
				perspective: 1000;
				height: 300rpx;

				>view {
					@include flexs();
					color: #7a642c;
					transition: 0.6s;
					transform-style: preserve-3d;

					&:nth-child(2) {
						margin-top: 10rpx;
					}

					>view {
						letter-spacing: 0;
						font-size: 120rpx;
						line-height: 1;
						font-weight: 900;
						color: #35AA4C;
						// margin-top: 20rpx;
						@include flexs();

						&:nth-child(2),
						&:nth-child(4) {
							margin: 0 10rpx;
						}
					}

					.card {
						letter-spacing: 0;
						font-size: 120rpx;
						line-height: 1;
						font-weight: bold;
						color: #35AA4C;
						transform-origin: bottom;

						// animation-iteration-count: infinite;
						animation: show 1s infinite;
					}
				}

				// /deep/.uni-countdown__number{
				// 	font-weight: 900;
				// 	// border:1rpx solid #EC3F10;
				// 	box-shadow: 5rpx 5rpx #EC3F10;
				// 	// box-shadow: 0rpx 0rpx 10rpx #EC3F10;
				// }
			}
		}

		.store_title {
			margin: 0 30rpx;
		}

		.store_title,
		.buildings_title {
			font-size: 28rpx;
			font-weight: 600;
			color: #000;

		}

		// 商家列表
		.hotelBox {
			padding: 0 20rpx;
		}

		.hotellList {
			border-radius: 30rpx;
			padding: 20rpx;
			margin: 20rpx 0 10rpx;
			background-color: #fff;
			box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
			// margin-bottom: 40rpx;

			.hotelInfo {
				@include flexs();
				position: relative;

				.fixBox {
					width: 100%;
					height: 100%;
					position: absolute;
					left: 0;
					top: 0;
					background-color: rgba(0, 0, 0, 0.55);
					color: #fff;
					font-size: 32rpx;
					@include flexs(center, center);
				}

				image {
					width: 144rpx;
					height: 144rpx;
					border-radius: 10rpx;
					flex-shrink: 0;
				}

				.topRight {
					width: calc(100% - 164rpx);
					margin-left: 20rpx;
					@include flexs(space-between, flex-start);
					flex-direction: column;

					.coupons {
						font-size: 20rpx;
						color: #fff;
						// @include flexs(space-between, center);
						display: flex;
						flex-wrap: wrap;

						&>view {
							background: #EB5B1E;
							// margin-right: 10rpx;
							margin: 10rpx 8rpx 0 0;
							padding: 8rpx 10rpx;
							border-radius: 10rpx;
							white-space: nowrap;

							&:nth-child(2n) {
								margin-right: 0;
							}

							text {
								padding-left: 8rpx;
								margin-left: 8rpx;
								border-left: 1rpx solid #fff;
							}
						}

						.received {
							background: #ccc;
						}
					}

					>view:nth-child(1) {
						width: 100%;
						@include flexs(space-between, center);

						>view:nth-child(1) {
							font-size: 32rpx;
							font-weight: bold;
							flex: 1;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}

						>.notEnd {
							@include flexs(flex-end, center);
							flex-shrink: 0;
							font-size: 22rpx;
							border-radius: 10rpx;
							border: 1px solid rgba(238, 238, 238, 1);

							>view:nth-child(1) {
								// background: linear-gradient(271.21deg, #f25b48 -4.12%, #f68758 99.23%);
								background: linear-gradient(89.48deg, rgba(252, 145, 107, 1) 0.33%, rgba(249, 75, 80, 1) 100.35%);
								color: #fff;
								padding: 10rpx;
								border-bottom-left-radius: 5rpx;
								border-top-left-radius: 5rpx;

							}

							>view:nth-child(2) {
								background: #fff;
								padding: 0 10rpx;
								color: #000;
								font-weight: bold;
								border-top-right-radius: 5rpx;
								border-bottom-right-radius: 5rpx;
							}
						}

						>.end {
							background-color: #e9ebed;
							border-radius: 10rpx;
							color: rgba(0, 0, 0, 0.55);
							font-size: 22rpx;
							padding: 10rpx;

							text {
								color: #040404;
								margin-left: 10rpx;
							}
						}
					}

					>view:nth-child(2) {
						width: 100%;
						@include flexs(space-between, center);
						font-size: 22rpx;
						padding: 20rpx 0;
					}

					>view:nth-child(3) {
						// @include flexs(flex-start, center);
						display: flex;
						font-size: 24rpx;
						width: 100%;

						>view {
							margin-right: 30rpx;

							&:first-child {
								margin-top: -4rpx;
							}

							&:last-child {
								color: #666;
							}
						}

						text {
							color: #FF1010;
							margin-left: 10rpx;
						}

					}

					// >view:nth-child(4) {
					// 	width: 100%;
					// 	@include flexs(space-between, center);
					// 	font-size: 22rpx;
					// 	line-height: 2;
					// }
				}
			}

			.shopContent {
				display: flex;
				// @include flexs(space-between, flex-start);
				padding: 20rpx 0 0;
				flex-wrap: wrap;
				// width: calc(100% - 160px);
				margin-left: 160rpx;

				.shopList {
					// width: calc((100% - 20rpx) / 3);
					margin-right: 30rpx;
					width: 126rpx;

					&:nth-child(3n) {
						margin-right: 0;
					}

					margin-bottom: 20rpx;

					.imgContent {
						// width: 44vw;
						// height: 44vw;
						width: 126rpx;
						height: 126rpx;
						// padding-bottom: calc(30 / 38 * 100%);
						position: relative;
						border-radius: 10rpx;
						overflow: hidden;

						.must {
							position: absolute;
							right: 10rpx;
							top: 10rpx;
							background-color: #35AA4C;
							color: #fff;
							font-size: 20rpx;
							border-radius: 5rpx;
							padding: 0 10rpx;
							line-height: 1.5;
							font-weight: bold;
						}

						image {
							position: absolute;
							left: 0;
							top: 0;
							bottom: 0;
							right: 0;
							max-width: 100%;
							max-height: 100%;
							margin: auto;
							width: auto;
							height: auto;
						}
					}
				}

				.shopInfo {
					padding: 10rpx 0;

					.shopName {
						font-size: 20rpx;
						line-height: 1.5;
						margin-bottom: 10rpx;
						// text-overflow: ellipsis;
						// overflow: hidden;
						// white-space: nowrap;
					}

					.shopDescribe {
						min-height: 48rpx;
						font-size: 24rpx;
						line-height: 2;
						color: rgba(0, 0, 0, 0.35);
						margin-bottom: 10rpx;
						text-overflow: ellipsis;
						overflow: hidden;
						white-space: nowrap;
					}

					.control {
						@include flexs(space-between, center);
						font-size: 24rpx;
						position: relative;

						.surplus {
							color: rgba(0, 0, 0, 0.55);
							@include flexs(flex-start, center);
							flex-wrap: wrap;
						}

						.price {
							font-size: 24rpx;
							color: #fa690a;
							font-weight: bold;
							margin-right: 10rpx;

							text {
								font-size: 24rpx;
								font-weight: 400;
							}
						}

						.specConetnt {
							background: #35AA4C;
							border-radius: 4px;
							padding: 15rpx 10rpx;
							color: #fff;
						}

						.num {
							width: 30rpx;
							height: 30rpx;
							font-size: 20rpx;
							border-radius: 50%;
							background-color: #f60000;
							position: absolute;
							right: -10rpx;
							top: -10rpx;
							line-height: 30rpx;
							text-align: center;
							color: #fff;
						}

						// .showInput {
						// 	width: 45%;
						// 	// justify-content: 
						// 	@include flexs(space-around, center);
						// 	color: #000000;
						// 	border-radius: 50rpx;
						// 	border: 1px solid #ccc;
						// 	padding: 0 8rpx;
						// 	overflow: hidden;

						// 	button {
						// 		width: 50rpx;
						// 		height: 50rpx;
						// 		line-height: 50rpx;
						// 		text-align: center;
						// 		font-size: 50rpx;
						// 		position: relative;
						// 		background: #fff;

						// 		&.down,
						// 		&.add {

						// 			&::before {
						// 				content: '';
						// 				position: absolute;
						// 				top: 50%;
						// 				left: 50%;
						// 				transform: translate(-50%, -50%);
						// 				width: 25rpx;
						// 				height: 5rpx;
						// 				border-radius: 10rpx;
						// 				background: #666;
						// 			}
						// 		}
						// 		&.down {
						// 			&::after {
						// 				content: '';
						// 				border: none;
						// 			}
						// 		}
						// 		&.add {
						// 			&::after {
						// 				content: '';
						// 				position: absolute;
						// 				top: 50%;
						// 				left: 50%;
						// 				transform: translate(-50%, -50%);
						// 				width: 5rpx;
						// 				height: 25rpx;
						// 				border-radius: 5rpx;
						// 				background: #666;
						// 			}
						// 		}
						// 	}

						// 	input {
						// 		width: calc(100% - 70rpx);
						// 		text-align: center;
						// 		height: 50rpx;
						// 		min-height: 50rpx;
						// 		line-height: 50rpx;
						// 	}
						// }
					}
				}
			}

			.more {
				text-align: center;
				font-size: 24rpx;
				@include flexs(center, center);
				border-top: 1px solid #eee;
				line-height: 2;
				padding-top: 20rpx;

				image {
					transform: rotate(0);
					width: 25rpx;
					height: 25rpx;
					margin-left: 10rpx;
				}
			}
		}



	}
</style>